package servlet.newsType;

import dao.NewsTypeDao;
import entity.NewsType;
import util.GetParamToClass;
import util.R;
import util.ResposeUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UpdateServlet extends HttpServlet {
    NewsTypeDao newsTypeDao = new NewsTypeDao();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        NewsType newsType = (NewsType) GetParamToClass.setObjectFiled(req,NewsType.class);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = df.format(new Date());
        newsType.setUpdateTime(time);
        int insert = newsTypeDao.update(newsType);
        R r = null;
        if (insert>0) {
            r = new R(R.CODE_SUCCESS, null,R.MSG_SUCCESS);
        } else {
            r = new R(R.CODE_ERR, null,R.MSG_ERR);
        }
        ResposeUtil.write(r,resp);
    }
}
